package cm.mefobe.android.telecomcost.adapter;

import java.util.ArrayList;
import java.util.List;

import cm.mefobe.android.telecomcost.entities.DailyThreshold;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class DailyThresholdAdapter extends ArrayAdapter<DailyThreshold> {
	protected ArrayList<DailyThreshold> items;
	protected Context _context;

	public DailyThresholdAdapter(Context context, int textViewResourceId,
			ArrayList<DailyThreshold> items, Activity activity) {
		super(context, textViewResourceId, items);
		this.items = items;
		_context = context;
	}

	/**
	 * @param context
	 * @param resource
	 * @param textViewResourceId
	 * @param objects
	 */
	public DailyThresholdAdapter(Context context, int resource,
			int textViewResourceId, ArrayList<DailyThreshold> objects) {
		super(context, resource, textViewResourceId, objects);
		this.items = objects;
		_context = context;
	}

	/**
	 * @param context
	 * @param resource
	 * @param textViewResourceId
	 */
	public DailyThresholdAdapter(Context context, int resource,
			int textViewResourceId) {
		super(context, resource, textViewResourceId);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public DailyThresholdAdapter(Context context, int textViewResourceId,
			List<DailyThreshold> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public DailyThresholdAdapter(Context context, int textViewResourceId,
			DailyThreshold[] objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 */
	public DailyThresholdAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			Log.i("DailyThresholdAdapter", "getting new Threshold_row_view");
			LayoutInflater vi = (LayoutInflater) _context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(
					cm.mefobe.android.telecomcost.R.layout.threshold_view,
					null);
		} else {
			Log.i("DailyThresholdAdapter",
					"getting existing Threshold_row_view");
		}
		DailyThreshold threshold = items.get(position);
		if (threshold != null) {
			TextView txtTitle = (TextView) v
					.findViewById(cm.mefobe.android.telecomcost.R.id.lblThreshold);
			txtTitle.setText(threshold.getDayNameLong());
			TextView txtAmount = (TextView) v
					.findViewById(cm.mefobe.android.telecomcost.R.id.lblAmount);
			txtAmount.setText(Double.toString(threshold.getAmount()));
		}
		return v;
	}
}
